<?php if ( ! defined('APPPATH')) exit('No direct script access allowed');
/**
 *      [PinTuXiu] (C)2001-2099 ONightjar.com Pintuxiu.com.
 *      This is NOT a freeware, use is subject to license terms
*/

class channel_controller extends PZ_Controller {

	public function __construct() {
		parent::__construct();
		$this->authfunctions = array('imagefetch','videofetch');
	}

	public function imagefetch(){
		$remote_url = trim($this->param('remote_url'));
		if(strpos($remote_url, 'taobao')||strpos($remote_url, 'tmall')){
			$type = 'taobao';
			$api = load_api('channel/taobao');
		}else{
			$type = 'web';
			$api = load_api('channel/web');
		}
		if($api){
			$url = pzurlencode($remote_url);
			$data = $api->fetchurl($url);
		}
		if($data){
			$data['type'] = $type;
			$this->ajax_success_response($data);
		}else{
			$this->ajax_failed_response(lang('publish_fetch_faild','tip'));
		}

	}

	public function videofetch(){
		$remote_url = trim($this->param('remote_url'));
		$remote_url = pzurlencode($remote_url);
		$data = load_api('channel/video')->parse($remote_url);
		if($data['flv']){
			$data['type'] = 'video';
			$this->ajax_success_response($data);
		}else{
			$this->ajax_failed_response(lang('publish_fetch_faild','tip'));
		}
		return;
	}

}